
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Django入门与实践-第9章：静态文件设置 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Fundamentals-4.html" />
    
    
    <link rel="prev" href="Fundamentals-3-1-1.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="GettingStarted.html">
            
                <a href="GettingStarted.html">
            
                    
                    Django入门与实践-第1章：环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="GettingStarted-2.html">
            
                <a href="GettingStarted-2.html">
            
                    
                    Django入门与实践-第2章：创建项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="gettingstarted-3.html">
            
                <a href="gettingstarted-3.html">
            
                    
                    Django入门与实践-第3章：Hello World
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="Fundamentals-1.html">
            
                <a href="Fundamentals-1.html">
            
                    
                    Django入门与实践-第4章：系统设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="Fundamentals-2.html">
            
                <a href="Fundamentals-2.html">
            
                    
                    Django入门与实践-第5章：模型设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="Fundamentals-3-0.html">
            
                <a href="Fundamentals-3-0.html">
            
                    
                    Django入门与实践-第6章：第一个视图函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="Fundamentals-3-1.html">
            
                <a href="Fundamentals-3-1.html">
            
                    
                    Django入门与实践-第7章：模板引擎设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="Fundamentals-3-1-1.html">
            
                <a href="Fundamentals-3-1-1.html">
            
                    
                    Django入门与实践-第8章：第一个单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.10" data-path="Fundamentals-3-2.html">
            
                <a href="Fundamentals-3-2.html">
            
                    
                    Django入门与实践-第9章：静态文件设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="Fundamentals-4.html">
            
                <a href="Fundamentals-4.html">
            
                    
                    Django入门与实践-第10章：Django Admin 介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="AdvancedConcepts.html">
            
                <a href="AdvancedConcepts.html">
            
                    
                    Django入门与实践-第11章：URL 分发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="AdvancedConcept2.html">
            
                <a href="AdvancedConcept2.html">
            
                    
                    Django入门与实践-第12章：复用模板
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="AdvancedConcept3.html">
            
                <a href="AdvancedConcept3.html">
            
                    
                    Django入门与实践-第13章：表单处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="Authentication0.html">
            
                <a href="Authentication0.html">
            
                    
                    Django入门与实践-第14章：用户注册
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="Authentication1.html">
            
                <a href="Authentication1.html">
            
                    
                    Django入门与实践-第15章：用户注销
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="Authentication2.html">
            
                <a href="Authentication2.html">
            
                    
                    Django入门与实践-第16章：用户登录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="DjangoORM0.html">
            
                <a href="DjangoORM0.html">
            
                    
                    Django入门与实践-第17章：保护视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="DjangoORM1.html">
            
                <a href="DjangoORM1.html">
            
                    
                    Django入门与实践-第18章：实现主题回复列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="DjangoORM2.html">
            
                <a href="DjangoORM2.html">
            
                    
                    Django入门与实践-第19章：实现主题回复功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="DjangoORM3.html">
            
                <a href="DjangoORM3.html">
            
                    
                    Django入门与实践-第20章：查询结果集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="DjangoORM.html">
            
                <a href="DjangoORM.html">
            
                    
                    Django入门与实践-第21章：Django数据迁移
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="ClassBasedViews0.html">
            
                <a href="ClassBasedViews0.html">
            
                    
                    Django入门与实践-第22章：基于类的视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24" data-path="ClassBasedViews1.html">
            
                <a href="ClassBasedViews1.html">
            
                    
                    Django入门与实践-第23章：分页实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.25" data-path="ClassBasedViews2.html">
            
                <a href="ClassBasedViews2.html">
            
                    
                    Django入门与实践-第24章：我的账户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.26" data-path="ClassBasedViews3.html">
            
                <a href="ClassBasedViews3.html">
            
                    
                    Django入门与实践-第25章：Markdown支持
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.27" data-path="ClassBasedViews4.html">
            
                <a href="ClassBasedViews4.html">
            
                    
                    Django入门与实践-第26章：个性化设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.28" data-path="Deployment.html">
            
                <a href="Deployment.html">
            
                    
                    Django入门与实践-第27章：项目部署
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >Django入门与实践-第9章：静态文件设置</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="django&#x5165;&#x95E8;&#x6307;&#x5357;-&#x7B2C;9&#x7AE0;&#xFF1A;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x8BBE;&#x7F6E;">Django&#x5165;&#x95E8;&#x6307;&#x5357;-&#x7B2C;9&#x7AE0;&#xFF1A;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x8BBE;&#x7F6E;</h1>
<p>&#x9759;&#x6001;&#x6587;&#x4EF6;&#x662F;&#x6307; CSS&#xFF0C;JavaScript&#xFF0C;&#x5B57;&#x4F53;&#xFF0C;&#x56FE;&#x7247;&#x6216;&#x8005;&#x662F;&#x7528;&#x6765;&#x7EC4;&#x6210;&#x7528;&#x6237;&#x754C;&#x9762;&#x7684;&#x4EFB;&#x4F55;&#x5176;&#x4ED6;&#x8D44;&#x6E90;&#x3002;</p>
<p>&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;Django &#x672C;&#x8EAB;&#x662F;&#x4E0D;&#x8D1F;&#x8D23;&#x5904;&#x7406;&#x8FD9;&#x4E9B;&#x6587;&#x4EF6;&#x7684;&#xFF0C;&#x4F46;&#x662F;&#x4E3A;&#x4E86;&#x8BA9;&#x6211;&#x4EEC;&#x7684;&#x5F00;&#x53D1;&#x8FC7;&#x7A0B;&#x66F4;&#x8F7B;&#x677E;&#xFF0C;Django &#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E9B;&#x529F;&#x80FD;&#x6765;&#x5E2E;&#x52A9;&#x6211;&#x4EEC;&#x7BA1;&#x7406;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x3002;&#x8FD9;&#x4E9B;&#x529F;&#x80FD;&#x53EF;&#x5728; <code>INSTALLED_APPS</code> &#x7684; <strong>django.contrib.staticfiles</strong> &#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x4E2D;&#x627E;&#x5230;&#xFF08;&#x8BD1;&#x8005;&#xFF1A;Django&#x4E3A;&#x4E86;&#x4F7F;&#x5F97;&#x5F00;&#x53D1;&#x65B9;&#x4FBF;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5904;&#x7406;&#x9759;&#x6001;&#x6587;&#x4EF6;&#xFF0C;&#x800C;&#x5728;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E0B;&#xFF0C;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x4E00;&#x822C;&#x76F4;&#x63A5;&#x7531; Nginx &#x7B49;&#x53CD;&#x5411;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x5904;&#x7406;&#xFF0C;&#x800C;&#x5E94;&#x7528;&#x5DE5;&#x670D;&#x52A1;&#x5668;&#x4E13;&#x5FC3;&#x8D1F;&#x8D23;&#x5904;&#x7406;&#x5B83;&#x64C5;&#x957F;&#x7684;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#xFF09;&#x3002;</p>
<p>&#x5E02;&#x9762;&#x4E0A;&#x5F88;&#x591A;&#x4F18;&#x79C0;&#x524D;&#x7AEF;&#x7EC4;&#x4EF6;&#x6846;&#x67B6;&#xFF0C;&#x6211;&#x4EEC;&#x6CA1;&#x6709;&#x7406;&#x7531;&#x7EE7;&#x7EED;&#x7528;&#x7B80;&#x964B;&#x7684;HTML&#x6587;&#x6863;&#x6765;&#x6E32;&#x67D3;&#x3011;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x8F7B;&#x677E;&#x5730;&#x5C06;Bootstrap 4&#x6DFB;&#x52A0;&#x5230;&#x6211;&#x4EEC;&#x7684;&#x9879;&#x76EE;&#x4E2D;&#x3002;Bootstrap&#x662F;&#x4E00;&#x4E2A;&#x7528;HTML&#xFF0C;CSS&#x548C;JavaScript&#x5F00;&#x53D1;&#x7684;&#x524D;&#x7AEF;&#x5F00;&#x6E90;&#x5DE5;&#x5177;&#x5305;&#x3002;</p>
<p>&#x5728;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;&#x4E2D;&#xFF0C;&#x9664;&#x4E86; boards, templates &#x548C;myproject&#x6587;&#x4EF6;&#x5939;&#x5916;&#xFF0C;&#x518D;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;static&#x7684;&#x65B0;&#x6587;&#x4EF6;&#x5939;&#xFF0C;&#x5E76;&#x5728;static&#x6587;&#x4EF6;&#x5939;&#x5185;&#x521B;&#x5EFA;&#x53E6;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;css&#x7684;&#x6587;&#x4EF6;&#x5939;&#xFF1A;</p>
<pre><code class="lang-shell">myproject/
 |-- myproject/
 |    |-- boards/
 |    |-- myproject/
 |    |-- templates/
 |    |-- static/       &lt;-- here
 |    |    +-- css/     &lt;-- and here
 |    +-- manage.py
 +-- venv/
</code></pre>
<p> &#x8F6C;&#x5230;<a href="https://getbootstrap.com/docs/4.0/getting-started/download/#compiled-css-and-js" target="_blank">getbootstrap.com</a>&#x5E76;&#x4E0B;&#x8F7D;&#x6700;&#x65B0;&#x7248;&#x672C;&#xFF1A;</p>
<p><img src="statics/bootstrap-download.png" alt="bootstrap"></p>
<p>&#x4E0B;&#x8F7D;&#x7F16;&#x8BD1;&#x7248;&#x672C;&#x7684;CSS&#x548C;JS</p>
<p>&#x5728;&#x4F60;&#x7684;&#x8BA1;&#x7B97;&#x673A;&#x4E2D;&#xFF0C;&#x89E3;&#x538B; bootstrap-4.0.0-beta-dist.zip &#x6587;&#x4EF6;&#xFF0C;&#x5C06;&#x6587;&#x4EF6; css/bootstrap.min.css &#x590D;&#x5236;&#x5230;&#x6211;&#x4EEC;&#x9879;&#x76EE;&#x7684;css&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#xFF1A;</p>
<pre><code class="lang-python">myproject/
 |-- myproject/
 |    |-- boards/
 |    |-- myproject/
 |    |-- templates/
 |    |-- static/
 |    |    +-- css/
 |    |         +-- bootstrap.min.css    &lt;-- here
 |    +-- manage.py
 +-- venv/
</code></pre>
<p> &#x4E0B;&#x4E00;&#x6B65;&#x662F;&#x544A;&#x8BC9;Django&#x5728;&#x54EA;&#x91CC;&#x53EF;&#x4EE5;&#x627E;&#x5230;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x3002;&#x6253;&#x5F00;settings.py&#xFF0C;&#x62C9;&#x5230;&#x6587;&#x4EF6;&#x7684;&#x5E95;&#x90E8;&#xFF0C;&#x5728;<strong>STATIC_URL</strong>&#x540E;&#x9762;&#x6DFB;&#x52A0;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;&#xFF1A;</p>
<pre><code class="lang-python"> STATIC_URL = <span class="hljs-string">&apos;/static/&apos;</span>

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, <span class="hljs-string">&apos;static&apos;</span>),
]
</code></pre>
<p>&#x8FD8;&#x8BB0;&#x5F97; <strong>TEMPLATES</strong>&#x76EE;&#x5F55;&#x5417;&#xFF0C;&#x548C;&#x8FD9;&#x4E2A;&#x914D;&#x7F6E;&#x662F;&#x4E00;&#x6837;&#x7684;</p>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x5728;&#x6A21;&#x677F;&#x4E2D;&#x52A0;&#x8F7D;&#x9759;&#x6001;&#x6587;&#x4EF6;&#xFF08;Bootstrap CSS&#x6587;&#x4EF6;&#xFF09;&#xFF1A;</p>
<p><strong>templates/home.html</strong></p>
<pre><code class="lang-html">{% load static %}<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;utf-8&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Boards<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% static &apos;css/bootstrap.min.css&apos; %}&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Boards<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">border</span>=<span class="hljs-string">&quot;1&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">thead</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Board<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Posts<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Topics<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Last Post<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">thead</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span>&gt;</span>
    {% for board in boards %}
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>
                {{ board.name }}<span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">small</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;color: #888&quot;</span>&gt;</span>{{ board.description }}<span class="hljs-tag">&lt;/<span class="hljs-name">small</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>0<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>0<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    {% endfor %}
    <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>&#x9996;&#x5148;&#xFF0C;&#x6211;&#x4EEC;&#x5728;&#x6A21;&#x677F;&#x7684;&#x5F00;&#x5934;&#x4F7F;&#x7528;&#x4E86; Static Files App &#x6A21;&#x677F;&#x6807;&#x7B7E; <code>{% load static %}</code>&#x3002;</p>
<p>&#x6A21;&#x677F;&#x6807;&#x7B7E;<code>{% static %}</code>&#x7528;&#x4E8E;&#x6784;&#x6210;&#x8D44;&#x6E90;&#x6587;&#x4EF6;&#x5B8C;&#x6574;URL&#x3002;&#x5728;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;<code>{% static &apos;css/bootstrap.min.css&apos; %}</code>&#x5C06;&#x8FD4;&#x56DE; <strong>/static/css/bootstrap.min.css</strong>&#xFF0C;&#x5B83;&#x76F8;&#x5F53;&#x4E8E; <a href="http://127.0.0.1:8000/static/css/bootstrap.min.css&#x3002;" target="_blank">http://127.0.0.1:8000/static/css/bootstrap.min.css&#x3002;</a></p>
<p><code>{% static %}</code>&#x6A21;&#x677F;&#x6807;&#x7B7E;&#x4F7F;&#x7528; settings.py&#x6587;&#x4EF6;&#x4E2D;&#x7684; <code>STATIC_URL</code> &#x914D;&#x7F6E;&#x6765;&#x7EC4;&#x6210;&#x6700;&#x7EC8;&#x7684;URL&#xFF0C;&#x4F8B;&#x5982;&#xFF0C;&#x5982;&#x679C;&#x60A8;&#x5C06;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x6258;&#x7BA1;&#x5728;&#x50CF; <a href="https://static.example.com/" target="_blank">https://static.example.com/</a> &#x8FD9;&#x6837;&#x7684;&#x5B50;&#x57DF;&#x4E2D; &#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x5C06;&#x8BBE;&#x7F6E; <code>STATIC_URL=https://static.example.com/</code> &#xFF0C;&#x7136;&#x540E; <code>{% static &apos;css/bootstrap.min.css&apos; %}</code>&#x8FD4;&#x56DE;&#x7684;&#x662F; <strong><a href="https://static.example.com/css/bootstrap.min.css" target="_blank">https://static.example.com/css/bootstrap.min.css</a></strong></p>
<p>&#x5982;&#x679C;&#x76EE;&#x524D;&#x8FD9;&#x4E9B;&#x5BF9;&#x4F60;&#x6765;&#x8BF4;&#x641E;&#x4E0D;&#x61C2;&#x4E5F;&#x4E0D;&#x8981;&#x62C5;&#x5FC3;&#x3002;&#x53EA;&#x8981;&#x8BB0;&#x5F97;&#x4F46;&#x51E1;&#x662F;&#x9700;&#x8981;&#x5F15;&#x7528;CSS&#xFF0C;JavaScript&#x6216;&#x56FE;&#x7247;&#x6587;&#x4EF6;&#x7684;&#x5730;&#x65B9;&#x5C31;&#x4F7F;&#x7528;<code>{% static %}</code>&#x3002;&#x7A0D;&#x540E;&#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x5F00;&#x59CB;&#x90E8;&#x7F72;&#x9879;&#x76EE;&#x5230;&#x6B63;&#x5F0F;&#x73AF;&#x5883;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x8BA8;&#x8BBA;&#x66F4;&#x591A;&#x3002;&#x73B0;&#x5728;&#x90FD;&#x8BBE;&#x7F6E;&#x597D;&#x4E86;&#x3002;</p>
<p>&#x5237;&#x65B0;&#x9875;&#x9762; <a href="http://127.0.0.1:8000" target="_blank">http://127.0.0.1:8000</a> &#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x5B83;&#x53EF;&#x4EE5;&#x6B63;&#x5E38;&#x8FD0;&#x884C;&#xFF1A;</p>
<p><img src="statics/boards-homepage-bootstrap.png" alt="b"></p>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7F16;&#x8F91;&#x6A21;&#x677F;&#xFF0C;&#x4EE5;&#x5229;&#x7528;Bootstrap CSS&#xFF1A;</p>
<pre><code class="lang-html">{% load static %}<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;utf-8&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Boards<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% static &apos;css/bootstrap.min.css&apos; %}&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ol</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;breadcrumb my-4&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;breadcrumb-item active&quot;</span>&gt;</span>Boards<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">ol</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;table&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">thead</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;thead-inverse&quot;</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Board<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Posts<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Topics<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Last Post<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">thead</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span>&gt;</span>
          {% for board in boards %}
            <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>
                {{ board.name }}
                <span class="hljs-tag">&lt;<span class="hljs-name">small</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;text-muted d-block&quot;</span>&gt;</span>{{ board.description }}<span class="hljs-tag">&lt;/<span class="hljs-name">small</span>&gt;</span>
              <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;align-middle&quot;</span>&gt;</span>0<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">td</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;align-middle&quot;</span>&gt;</span>0<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
          {% endfor %}
        <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>&#x663E;&#x793A;&#x6548;&#x679C;&#xFF1A;</p>
<p><img src="statics/boards-homepage-bootstrap-2.png" alt=""></p>
<p>&#x5230;&#x76EE;&#x524D;&#x4E3A;&#x6B62;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x4EA4;&#x4E92;&#x5F0F;&#x63A7;&#x5236;&#x53F0;&#xFF08;python manage.py shell&#xFF09;&#x6DFB;&#x52A0;&#x4E86;&#x51E0;&#x4E2A;&#x65B0;&#x7684;&#x7248;&#x5757;&#x3002;&#x4F46;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x66F4;&#x597D;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x5B9E;&#x73B0;&#x3002;&#x5728;&#x4E0B;&#x4E00;&#x8282;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x4E3A;&#x7F51;&#x7AD9;&#x7BA1;&#x7406;&#x5458;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x7BA1;&#x7406;&#x754C;&#x9762;&#x6765;&#x7BA1;&#x7406;&#x8FD9;&#x4E9B;&#x6570;&#x636E;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Fundamentals-3-1-1.html" class="navigation navigation-prev " aria-label="Previous page: Django入门与实践-第8章：第一个单元测试">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Fundamentals-4.html" class="navigation navigation-next " aria-label="Next page: Django入门与实践-第10章：Django Admin 介绍">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Django入门与实践-第9章：静态文件设置","level":"1.10","depth":1,"next":{"title":"Django入门与实践-第10章：Django Admin 介绍","level":"1.11","depth":1,"path":"Fundamentals-4.md","ref":"./Fundamentals-4.md","articles":[]},"previous":{"title":"Django入门与实践-第8章：第一个单元测试","level":"1.9","depth":1,"path":"Fundamentals-3-1-1.md","ref":"./Fundamentals-3-1-1.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["include-codeblock","livereload"],"pluginsConfig":{"include-codeblock":{"check":false,"edit":false,"fixlang":false,"lang":"","template":"default","theme":"chrome","unindent":false},"livereload":{},"highlight":{},"search":{},"lunr":{"ignoreSpecialCharacters":false,"maxIndexSize":1000000},"sharing":{"all":["facebook","google","instapaper","twitter","weibo"],"facebook":true,"google":false,"instapaper":false,"twitter":true,"vk":false,"weibo":false},"fontsettings":{"family":"sans","size":2,"theme":"white"},"theme-default":{"showLevel":false,"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}},"file":{"path":"Fundamentals-3-2.md","mtime":"2018-05-13T13:48:46.868Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-05-13T12:52:49.928Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

